package user;

import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import user.domain.model.User;
import user.infrastructure.repository.JpaUserRepository;

@SpringBootApplication
public class AgricultureUserApplication {

    @Autowired
    private JpaUserRepository jpaUserRepository;

    public static void main(String[] args) {
        SpringApplication.run(AgricultureUserApplication.class, args);
    }

    @PostConstruct
    public void initAdminUser() {
        String adminUsername = "YYO-CHO";
        if (!jpaUserRepository.existsByUsername(adminUsername)) {
            User admin = User.builder()
                    .username(adminUsername)
                    .password("12345678")
                    .realName("陈莹莹")
                    .email("15209296604@163.com")
                    .role("admin")
                    .avatar("")
                    .build();

            jpaUserRepository.save(admin);
            System.out.println("管理员账号已初始化: " + adminUsername);
        } else {
            System.out.println("管理员账号已存在: " + adminUsername + "，跳过初始化");
        }
    }


}
